<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>许飞音乐会报名汇总</title>
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	<link rel="stylesheet" href="dist/semantic.min.css">
	<style type="text/css">
		td,th{
			border: 1px solid #E9E4E4;
		}
	</style>
</head>
<body>
	<img src="./xff.jpg" alt="" width="0" height="0">
	<div class="ui container">
		<div class="ui statistics">
		
		  <div class="statistic two red">
		    <div class="value" id="zrs">     
		    </div>
		    <div class="label">已报名人数 </div>
		  </div>
		  <div class="statistic red right floated ">
		    <div class="value" id="zje">
		      
		    </div>
		    <div class="label">应援总金额</div>
		  </div>
	
		</div>
		<img class="ui centered rounded small image" src="dist/1.png">
		<h3 class="ui center aligned red icon header">
			请添加负责人微信进入活动群
		</h3>
		<button class="ui green button admin" id="admin">以管理员身份查看</button>
		<div class="ui divider"></div>
			<div class="ui input focus transition hidden mycode">
			  <input type="text" placeholder="请输入管理员秘钥..." id="mycode">
			  <button class="ui teal button" id="send">确定</button>
			</div>	
		<button class="ui violet button transition hidden exc" onclick="method5('tab')">将表格以Excel格式导出</button>
		<table class="ui striped table transition hidden tab" id="tab">
	  
		</table>
		<div class="ui relaxed divided list  transition hidden myul" id="myul">
		 
		</div>
	</div>


	<script type="text/javascript" src="dist/jquery-1.12.4.min.js"></script>
	<script type="text/javascript" src="dist/semantic.min.js"></script>
	<script type="text/javascript">
	$(function(){


	$("#admin").click(function(event) {
		$(".mycode").transition('browse right')
	});
	$("#send").click(function(event) {
		var mycode=$("#mycode").val();
		getData(mycode);
	});
	getData();


	function getData(str){
		var zongPeople=0;
		var zongMoney=0;
		$.ajax({
				url: 'http://runningh5.top/xf/xufeiapi/table.php',
				type: 'GET',
				dataType:'json',
				data: {key:str},
				success:function(data){
					console.log(data)
					if(data.code==1){
							$(".mycode").transition('browse right')
							$(".admin").transition('browse right')
							$(".exc").transition('browse right')
							$(".myul").transition('fade left');
							$(".tab").transition('fade left');
							$("#tab").empty();
							$("<thead>").html(`
								    <tr>
									    <th>序号</th>
									    <th>昵称</th>
									    <th>微信号</th>
									    <th>手机号</th>
									    <th>人数</th>
									    <th>金额</th>
									    <th>截图</th>
									    <th>报名时间</th>
									    <th>管理</th>
								  	</tr>
								`).appendTo('#tab');
							$.each(data.data, function(index, val) {
								 var timer=new Date((val.addtime)*1000);
								 var mytime=timer.getFullYear()+'/'+(timer.getMonth()+1)+'/'+timer.getDate()+" "+timer.getHours()+":"+timer.getMinutes()+":"+timer.getSeconds();
								 var img=val.image!=""?"<a href='http://runningh5.top/xf/xufeiapi/images/"+val.image+"' target='_blank'><img src='http://runningh5.top/xf/xufeiapi/images/"+val.image+"' class='ui mini image'></a>":"";
								 zongPeople +=Number(val.num);
								 zongMoney +=Number(val.money);
								 $("<tbody>").html(`
								    <tr>
								      <td>`+(index+1)+`</td>
								      <td>`+val.name+`</td>
								      <td>`+val.weixin+`</td>
								      <td>`+val.phone+`</td>
								      <td>`+val.num+`</td>
								      <td>¥: `+val.money+`</td>
								      <td>`+img+`</td>
								      <td>`+mytime+`</td>
								      <td><a href='action.php?id=`+val.id+`'>操作</a></td>
								    </tr>
								`).appendTo('#tab');
							});
						}else{
							// $(".tab").transition('fade left');
							$(".myul").transition('fade left');
							$("#myul").empty();
							
							$.each(data.data, function(index, val) {
								 var timer=new Date((val.addtime)*1000);
								 var mytime=timer.getFullYear()+'/'+(timer.getMonth()+1)+'/'+timer.getDate()+" "+timer.getHours()+":"+timer.getMinutes()+":"+timer.getSeconds();
								 zongPeople +=Number(val.num);
								 zongMoney +=Number(val.money);
								 $("<div class='item'>").html(`
									    <i class='large wechat green middle aligned icon'></i>
									    <div class='content'>
									      <div class='header'>昵称: `+val.name+`</div>
									   
									      <div class='description'>人数: `+val.num+`</div>
									       
									    
									    </div>
								 	`).appendTo("#myul")
							});
						}
						$("#zrs").html(zongPeople);
						$("#zje").html(zongMoney.toFixed(2));
				},
				error:function(err){
					console.log(err)
					alert("获取数据失败!请重试");
				}
			})

	}

   })
	var idTmr;  
        function  getExplorer() {  
            var explorer = window.navigator.userAgent ;  
            //ie  
            if (explorer.indexOf("MSIE") >= 0) {  
                return 'ie';  
            }  
            //firefox  
            else if (explorer.indexOf("Firefox") >= 0) {  
                return 'Firefox';  
            }  
            //Chrome  
            else if(explorer.indexOf("Chrome") >= 0){  
                return 'Chrome';  
            }  
            //Opera  
            else if(explorer.indexOf("Opera") >= 0){  
                return 'Opera';  
            }  
            //Safari  
            else if(explorer.indexOf("Safari") >= 0){  
                return 'Safari';  
            }  
        }  
        function method5(tableid) {  
            if(getExplorer()=='ie')  
            {  
                var curTbl = document.getElementById(tableid);  
                var oXL = new ActiveXObject("Excel.Application");  
                var oWB = oXL.Workbooks.Add();  
                var xlsheet = oWB.Worksheets(1);  
                var sel = document.body.createTextRange();  
                sel.moveToElementText(curTbl);  
                sel.select();  
                sel.execCommand("Copy");  
                xlsheet.Paste();  
                oXL.Visible = true;  
  
                try {  
                    var fname = oXL.Application.GetSaveAsFilename("Excel.xls", "Excel Spreadsheets (*.xls), *.xls");  
                } catch (e) {  
                    print("Nested catch caught " + e);  
                } finally {  
                    oWB.SaveAs(fname);  
                    oWB.Close(savechanges = false);  
                    oXL.Quit();  
                    oXL = null;  
                    idTmr = window.setInterval("Cleanup();", 1);  
                }  
  
            }  
            else  
            {  
                tableToExcel(tableid)  
            }  
        }  
        function Cleanup() {  
            window.clearInterval(idTmr);  
            CollectGarbage();  
        }  
        var tableToExcel = (function() {  
            var uri = 'data:application/vnd.ms-excel;base64,',  
                    template = '<html><head><meta charset="UTF-8"></head><body><table>{table}</table></body></html>',  
                    base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) },  
                    format = function(s, c) {  
                        return s.replace(/{(\w+)}/g,  
                                function(m, p) { return c[p]; }) }  
            return function(table, name) {  
                if (!table.nodeType) table = document.getElementById(table)  
                var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}  
                window.location.href = uri + base64(format(template, ctx))  
            }  
        })()

     
	</script>
</body>
</html>